﻿#include "Graphics.h"
#include "Engine.h"
#include "Common.h"
#include "Resources.h"
#include "Geometry.h";

#include "TestScene.h"
#include <iostream>
#include <vector>

using namespace DYEngine;
using namespace DYGraphics;

void UpdateCamera();
void UpdateSceneElements();
void RenderScene();
void UpdateFrame();

void InputEventEmit();
void WindowSizeChange(int width, int height);
void CursorMoveEvent(float xPos, float yPos);
void KeyPressEvent(int key, int action);
void MouseButtonEvent(int button, int action);
void ScrollEvent(float xoffset, float yoffset);

TestScene* scene;

int main(int argc, char* argv[])
{
	DeviceConfig config;
	config.winName = "DYEngine";
	config.winWidth = 800;
	config.winHeight = 600;
	config.updateCameraCb = UpdateCamera;
	config.updateSceneCb = UpdateSceneElements;
	config.renderSceneCb = RenderScene;
	config.updateFrameCb = UpdateFrame;
	config.inputEventEmit = InputEventEmit;
	config.sizeChangeCb = WindowSizeChange;
	config.cursorMoveCb = CursorMoveEvent;
	config.keyCb = KeyPressEvent;
	config.mouseButtonCb = MouseButtonEvent;
	config.scrollCb = ScrollEvent;

	Camera::sWidth = 800;
	Camera::sHeight = 600;

	if (!Device::Init(config)) {
		std::cout << "init render device fails!" << std::endl;
		return -1;
	}

	scene = new TestScene();
	scene->Load();

	Time::Init();
	Device::Loop();

	delete scene;
	Device::Destroy();
	return 0;
}



void UpdateCamera()
{

}

void UpdateSceneElements()
{
	scene->Update();
}

void RenderScene()
{
	RenderDevice::Draw();
}

void UpdateFrame()
{
	Time::Update();
}

void InputEventEmit()
{
	Input::Emit();
}

void WindowSizeChange(int width, int height)
{
	Camera::sWidth = width;
	Camera::sHeight = height;
	Camera* mainCam = Camera::GetMainCamera();
	mainCam->SetAspect((float)width / height);
	Input::ScreenSizeChange(width, height);
}

void CursorMoveEvent(float xPos, float yPos)
{
	Input::CursorMove(xPos, yPos);
}

void KeyPressEvent(int key, int action)
{
	Input::KeyPress(key, action);
}

void MouseButtonEvent(int button, int action)
{
	Input::MouseButtonPress(button, action);
}

void ScrollEvent(float xoffset, float yoffset)
{
	Input::ScrollEvent(xoffset, yoffset);
}